const ResponseUtil = require('../utils/ResponseUtil');
const formidable = require('formidable')


module.exports = (option, app) => {
    return async function errorHandler(ctx, next) {

      try {
        await next();
      } catch (err) {
      	const ip = ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress 
            || ctx.req.socket.remoteAddress || ctx.req.connection.socket.remoteAddress || ''
        ctx.app.logger.info('error found', ip, ctx.request.path, ctx.request.headers, ctx.request.query, ctx.request.body, err)
        ctx.body = ResponseUtil.resError(err.message)
      }
    };
  };
